<?php
    session_start();
    require 'common/Utility.php';
    require 'crud/CustomSecurity.class.php';
    require 'crud/Recepti.class.php';
    require 'crud/Recepta_helper.class.php';
    require 'crud/Categorii_recepti.class.php';
	require 'db/configuration.php';
	include_once("js/ajax/agent.php");
	loginCheck();
	loadDB();
	setcookie("rynyty[lastpage]", "recepti.php", time()+60*60*24*30);
	actions();
	$agent->init();
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"
   "http://www.w3.org/TR/html4/strict.dtd">

<html lang="bg">
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> 
    <link rel="stylesheet" type="text/css" href="css/page.css" />
	<link rel="stylesheet" href="js/fancybox/jquery.fancybox-1.2.5.css" type="text/css" media="screen"/>
	<link rel="stylesheet" type="text/css" href="js/jcarousel/lib/jquery.jcarousel.css" />
	<link rel="stylesheet" type="text/css" href="js/jcarousel/skins/tango/skin.css" />
	<link rel="stylesheet" type="text/css" href="css/recepti.css" />
	
	<script type="text/javascript" src="js/jquery-1.3.2.min.js"></script>
	<script type="text/javascript" src="js/jcarousel/lib/jquery.jcarousel.js"></script>
	<script type="text/javascript" src="js/categories.js"></script>
	<script type="text/javascript" src="js/components.js"> </script>
	<script type="text/javascript" src="js/util.js"></script>
	<script type="text/javascript" src="js/recepti.js"> </script>
	<script type="text/javascript" src="js/fancybox/jquery.fancybox-1.2.5.pack.js"></script>
	<title>Рецепти</title>
</head>
<body>	



<?php include("common/lenta.php"); ?>


<div id="main">
<div id="product-view">
	<div id="editnew-container"></div>
	<!-- <div id="logo"></div> -->
	<!-- <div id="logo-text"></div> -->
	<?php include("common/servizna-lenta.php"); ?>
	<div id="product-view-container">
		<?php include("common/servizna-lenta.php"); ?> 
		<script language="javascript" type="text/javascript" defer> 
			setSelected('recipes');	
		</script>
		<ul id="editnew">
			<li>
				<input id="moite" type="button" value="мои" class="editnew" onclick=""></input>
			</li>
			<li> 
				<input id="editbutton" type="button" value="редактиране" class="editnew" onclick="setEditMode();"></input>
			</li>
			<li>
				<div id="add">
				<a id="addButtonId" href="recepta.php?iframe">нова</a>
				</div>
			</li>
			<li>
				<input id="find" type="text" name="find" onkeyup="filterRecepti();" />
			</li>
		</ul>
		<div id="top">
			<?php
				$categories = new Categorii_recepti(con());
				$listCategories = $categories->getAllNames();
				if (isset($_SESSION['selReceptCateg'])){
					$selectedCategory = $_SESSION['selReceptCateg'];	
				} else {
					$selectedCategory = "ВСИЧКИ";
				}
				
				echo '<script language="javascript" type="text/javascript" defer> generateCategries_o('.json_encode($listCategories).', '.json_encode($selectedCategory).',\'changeRcategory\');</script>'  
			?>
		</div>
		<div id="middle">
			<div class="left"></div>
			<div id="maincontent" class="content">
			  			
<?php	
	echo '<script language="javascript" type="text/javascript" defer> list_table_recepti('.json_encode(getRecepti()).', '.$_SESSION['user_id'].');</script>'
?>
				<!-- kraj na recepti -->
				
			</div>
		</div>
		<div id="bottom">
			<div class="bottomleft">
			</div>
			<div class="bottommiddle">
			</div>
			<div class="bottomright">
			</div>
		</div>
	</div>		
	</div>
</div>

<script type="text/javascript">
jQuery(document).ready(function() {
	
	$('a#addButtonId').fancybox({
		'hideOnContentClick':false,
		'frameWidth':700,
		'frameHeight':500,
		'showCloseButton':true,
		'padding':0
	});

	$('a.thickbox').fancybox({
		'hideOnContentClick': false,
		'frameWidth': 700,
		'frameHeight': 500,
		'showCloseButton':true,
		'padding':0
	})

	resizerecepti();

});
</script>
<?php 

function deleteProducts($id){
	$crud = new Recepta_helper(con());
	$crud->remove($id);
} 
function change_category($catName){
	$_SESSION['selReceptCateg'] = $catName;
	return $catName;
}

function getRecepti(){
	$crudRecepti = new Recepti(con());
	if (isset($_SESSION['selReceptCateg']) && strcasecmp($_SESSION['selReceptCateg'], "ВСИЧКИ") !=0){
		$list = $crudRecepti->get($_SESSION['selReceptCateg']);
	} else {
		$list = $crudRecepti->getAll();
	}
	return $list;
}

function actions(){
	$crudRecepti = new Recepti(con());
	if(isset($_POST['id'])){
		deleteProducts($_POST['id']);
		$crudRecepti->remove($_POST['id']);
	}
}

?>

<script type="text/javascript">

  var _gaq = _gaq || [];
  _gaq.push(['_setAccount', 'UA-11565452-1']);
  _gaq.push(['_trackPageview']);

  (function() {
    var ga = document.createElement('script');
    ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
    ga.setAttribute('async', 'true');
    document.documentElement.firstChild.appendChild(ga);
  })();

  $(window).focus(function(){
	  clearTimeout(t);
	  t = setTimeout('check()', 2000);
  });

  function check(){
	  agent.call('','isSessionActive','sessionCallback');;
	}

  function sessionCallback(result){
	  if (result == 1){
	  } else {
		  setTimeout('delayer()', 1000);
	  }
		  
  }
  function delayer(){
//	    window.location = "./login.php";
	  window.location.reload(1);
	}

</script>
</body>
</html>
